import { ILoadMapTypeAll } from '@/common';
import { ManageCommonAPI } from '@/pages/type';
import { getLevelFirstJson, getLevelZeroJson, getSelectDataCommon, getSelectDataMapList, getTenantID } from '@/utils';

const getSearchList = (loadMdicMapList: Record<string, any>, queryTypeObj: Record<string, any>): ManageCommonAPI.ISearchList => {
  // 范本状态
  const stateList = getSelectDataCommon(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.CONTRACTTEMP_STATE}`], 'name', 'id');

  /** 合同类型 */
  const businessTypeList = getSelectDataMapList(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.CONTRACT_TYPE}`], 'name', 'id', true);

  /** 作废类型 */
  const cancelTypeList = getSelectDataCommon(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.CONTRACTTEMP_CANCELTYPE}`], 'name', 'id');

  let orgDeptList: any[] = [];
  if (queryTypeObj?.params == 'createCompanyID') {
    orgDeptList = getLevelZeroJson();
  } else if (queryTypeObj?.params == 'createDepartmentID') {
    orgDeptList = getLevelFirstJson();
  }

  return [
    {
      name: 'fullName',
      placeholder: '范本名称',
      label: '范本名称',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 0,
        fieldUse: 0,
        searchType: 0,
        seq: 0,
      },
    },
    {
      name: 'state',
      placeholder: '范本状态',
      label: '范本状态',
      componentType: 'Select',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      dataSource: stateList,
      searchParams: {
        fieldType: 'String',
        fieldParam: 1,
        fieldUse: 0,
        searchType: 1,
        seq: 0,
      },
    },
    {
      name: 'templateInfo',
      placeholder: '范本描述',
      label: '范本描述',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 0,
        fieldUse: 0,
        searchType: 0,
        seq: 0,
      },
    },
    // {
    //   name: 'templateType',
    //   placeholder: '范本类型',
    //   label: '范本类型',
    //   componentType: 'Select',
    //   allowClear: true,
    //   dataSource: templateTypeList,
    //   md: 4,
    //   sm: 24,
    //   whetherSenior: false,
    //   searchParams: {
    //     fieldType: 'String',
    //     fieldParam: 1,
    //     fieldUse: 0,
    //     searchType: 1,
    //     seq: 0,
    //   },
    // },
    {
      name: 'businessType',
      placeholder: '合同类型可搜索',
      label: '合同类型可搜索',
      componentType: 'TreeSelect',
      allowClear: true,
      dataSource: businessTypeList,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 1,
        fieldUse: 0,
        searchType: 1,
        seq: 0,
      },
    },
    {
      name: 'singTime',
      placeholder: '发布',
      label: '发布时间',
      componentType: 'RangePicker',
      allowClear: true,
      md: 8,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'Date',
        fieldParam: 0,
        fieldUse: 0,
        isSearch: 0,
        searchType: 0,
        seq: 0,
      },
    },
    {
      name: 'signFormName',
      placeholder: '发布',
      label: '发布',
      componentType: 'DeptAndUser',
      dataSource: orgDeptList,
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: true,
      formOrgType: {
        COMP: 'signCompanyID',
        DEPT: 'signDepartmentID',
        POS: 'signPositionID',
        USER: 'signerID',
      },
    },
    {
      name: 'signCompanyID',
      placeholder: '发布人公司',
      label: '发布人公司',
      componentType: 'QueryParams',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 5,
        fieldUse: 0,
        searchType: 2,
        seq: 0,
      },
    },
    {
      name: 'signDepartmentID',
      placeholder: '发布人部门',
      label: '发布人部门',
      componentType: 'QueryParams',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 4,
        fieldUse: 0,
        searchType: 2,
        seq: 0,
      },
    },
    {
      name: 'signPositionID',
      placeholder: '发布人岗位',
      label: '发布人岗位',
      componentType: 'QueryParams',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 3,
        fieldUse: 0,
        searchType: 2,
        seq: 0,
      },
    },
    {
      name: 'signerID',
      placeholder: '发布人',
      label: '发布人',
      componentType: 'QueryParams',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 1,
        fieldUse: 0,
        searchType: 2,
        seq: 0,
      },
    },
    {
      name: 'cancelTime',
      placeholder: '作废',
      label: '作废时间',
      componentType: 'RangePicker',
      allowClear: true,
      md: 12,
      sm: 24,
      whetherSenior: true,
      searchParams: {
        fieldType: 'Date',
        fieldParam: 0,
        fieldUse: 0,
        isSearch: 0,
        searchType: 0,
        seq: 0,
      },
    },
    {
      name: 'cancelType',
      placeholder: '作废类型',
      label: '作废类型',
      componentType: 'Select',
      allowClear: true,
      dataSource: cancelTypeList,
      md: 4,
      sm: 24,
      whetherSenior: true,
      searchParams: {
        fieldType: 'String',
        fieldParam: 1,
        fieldUse: 0,
        searchType: 1,
        seq: 0,
      },
    },
    {
      name: 'cancelReason',
      placeholder: '作废原因',
      label: '作废原因',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: true,
      searchParams: {
        fieldType: 'String',
        fieldParam: 0,
        fieldUse: 0,
        searchType: 0,
        seq: 0,
      },
    },

    {
      name: queryTypeObj?.params,
      placeholder: '权限参数',
      label: '权限参数',
      componentType: 'QueryParams',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        // fieldParam: 5,
        fieldParam:
          queryTypeObj?.params == 'createDepartmentID'
            ? 5
            : queryTypeObj?.params == 'createDepartmentID'
            ? '4'
            : queryTypeObj?.params == 'createrID'
            ? '2'
            : '3',
        fieldUse: 0,
        searchType: 2,
        seq: 0,
      },
    },
  ];
};

export { getSearchList };
